<?php
use_helper('I18N');
?>
<script type="text/javascript" language="javascript">
    var datagrid = null;
    var datagridDetail = null;
    $(function() {
        datagrid = $("#datagrid").r9jasonDataTable({
            // online1DataTable extra params
            "idTr" : true, // assign <tr id='xxx'> from 1st columns array(aoColumns);
            "extraParam" : function(aoData) { // pass extra params to server

            },
            "reassignEvent" : function() { // extra function for reassignEvent when JSON is back from server
                reassignDatagridDetailEventAttr();
            },

            // datatables params
            "bLengthChange": true,
            "bFilter": false,
            "bProcessing": true,
            "bServerSide": true,
            "bAutoWidth": false,
            "sAjaxSource": "/finance/bonusDetailLogList",
            "sPaginationType": "full_numbers",
            "aaSorting": [
                [0,'desc']
            ],
            "aoColumns": [
                { "sName" : "commission.created_on",  "bSortable": true},
                { "sName" : "_DRB",  "bSortable": true, "fnRender": function ( oObj ) {
                    return "<a class='detailLink' ref='" + oObj.aData[0] + "' transaction='DRB' href='#'>" + oObj.aData[1] + "</a>";
                }},
                { "sName" : "_ROI",  "bSortable": true, "fnRender": function ( oObj ) {
                    return "<a class='detailLink' ref='" + oObj.aData[0] + "' transaction='ROI' href='#'>" + oObj.aData[2] + "</a>";
                }},
                { "sName" : "_PIPS_BONUS",  "bSortable": true, "fnRender": function ( oObj ) {
                    return "<a class='detailLink' ref='" + oObj.aData[0] + "' transaction='PIPS BONUS' href='#'>" + oObj.aData[3] + "</a>";
                }},
                { "sName" : "SUB_TOTAL",  "bSortable": true}
            ]
        });

        datagridDetail = $("#datagridDetail").r9jasonDataTable({
            // online1DataTable extra params
            "idTr" : true, // assign <tr id='xxx'> from 1st columns array(aoColumns);
            "extraParam" : function(aoData) { // pass extra params to server
                aoData.push({ "name": "filterAction", "value": $("#textboxQueryAction").val() });
                aoData.push({ "name": "filterDate", "value": $("#textboxQueryDate").val() });
            },
            "reassignEvent" : function() { // extra function for reassignEvent when JSON is back from server
                reassignDatagridEventAttr();
            },

            // datatables params
            "bLengthChange": true,
            "bFilter": false,
            "bProcessing": true,
            "bServerSide": true,
            "bAutoWidth": false,
            "sAjaxSource": "/finance/bonusDetailList",
            "sPaginationType": "full_numbers",
            "aaSorting": [
                [0,'desc']
            ],
            "aoColumns": [
                { "sName" : "created_on",  "bSortable": true},
                { "sName" : "credit", "bVisible" : true,  "bSortable": true},
                { "sName" : "debit",  "bSortable": true},
                { "sName" : "balance",  "bSortable": true},
                { "sName" : "remark",  "bSortable": true}
            ]
        });
    }); // end function

    function reassignDatagridDetailEventAttr() {
        $(".detailLink").click(function(event) {
            event.preventDefault();

            $("#textboxQueryDate").val($(this).attr("ref"));
            $("#textboxQueryAction").val($(this).attr("transaction"));
            $("#divBonusDetail").show();
            datagridDetail.fnDraw();
        });
    }

    function reassignDatagridEventAttr() {
        $("a[id=editLink]").click(function(event) {

        });
    }
</script>
<div class="row">
    <div class="col-md-12">
        <h2 class="page-title"><?php echo __("Bonus Commission"); ?>
            <small></small>
        </h2>
    </div>
</div>
<div class="row">
    <div class="col-md-12">
        <section class="widget">
            <header>
                <h4>
                    <i class="icon-ok-sign"></i>
                    <?php echo __("Bonus Commission"); ?>
                    <small></small>
                </h4>
            </header>
            <div class="body">
                <fieldset>
                    <legend class="section">
                        <?php echo __("Bonus Commission")?>
                    </legend>
                    <?php include_component('component', 'alert', array('param' => $sf_user->getAttribute(Globals::SESSION_DISTID, 0))) ?>
                    <div class="row">
                        <div class="col-md-10 col-md-offset-1">
                            <section class="widget">
                                <header>
                                    <h4>
                                        <i class="icon-file-alt"></i>
                                        <?php echo __("Bonus Commission Listing")?>
                                    </h4>
                                </header>
                                <div class="body">
                                    <div>
                                        <table class="table table-striped" id="datagrid" border="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th><?php echo __('Date') ?></th>
                                                <th><?php echo __('DRB') ?></th>
                                                <th><?php echo __('ROI') ?></th>
                                                <th><?php echo __('Pips Bonus') ?></th>
                                                <th><?php echo __('Sub Total') ?></th>
                                            </tr>
                                            </thead>
                                        </table>
                                        <br>
                                        <br>
                                    </div>
                                </div>
                            </section>
                            <section class="widget">
                                <header>
                                    <h4>
                                        <i class="icon-file-alt"></i>
                                        <?php echo __("Bonus Commission Detail")?>
                                    </h4>
                                </header>
                                <div class="body">
                                    <div id="divBonusDetail" style="display: none">
                                        <input type="hidden" id="textboxQueryDate">
                                        <input type="hidden" id="textboxQueryAction">
                                        <table class="table table-striped" id="datagridDetail" border="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th><?php echo __('Date') ?></th>
                                                <th><?php echo __('In') ?></th>
                                                <th><?php echo __('Out') ?></th>
                                                <th><?php echo __('Balance') ?></th>
                                                <th><?php echo __('Remarks') ?></th>
                                            </tr>
                                            </thead>
                                        </table>
                                        <br>
                                        <br>
                                    </div>
                                </div>
                            </section>
                        </div>
                    </div>
                </fieldset>
                <!--<div class="form-actions">
                    <a href="/member/summary" class="btn btn-default"><?php /*echo __("Cancel");*/?></a>
                </div>-->
            </div>
        </section>
    </div>
</div>